#include <boost/asio.hpp>
#include <iostream>
#include <memory>
#include <functional>

using namespace boost::asio;

// 事件处理器接口
class EventHandler {
public:
    virtual ~EventHandler() = default;
    virtual void handleEvent() = 0;
};

// 定时器事件处理器
class TimerHandler : public EventHandler {
private:
    int id_;
    steady_timer timer_;
    
public:
    TimerHandler(io_context& io_ctx, int id, int interval_ms) 
        : id_(id), timer_(io_ctx) {
        timer_.expires_after(std::chrono::milliseconds(interval_ms));
        timer_.async_wait([this](const boost::system::error_code& ec) {
            if (!ec) {
                handleEvent();
            }
        });
    }
    
    void handleEvent() override {
        std::cout << "Timer " << id_ << " triggered!" << std::endl;
        // 重新设置定时器
        timer_.expires_after(std::chrono::milliseconds(1000));
        timer_.async_wait([this](const boost::system::error_code& ec) {
            if (!ec) {
                handleEvent();
            }
        });
    }
};

// 网络事件处理器
class NetworkHandler : public EventHandler {
private:
    ip::tcp::socket socket_;
    std::array<char, 1024> buffer_;
    
public:
    NetworkHandler(io_context& io_ctx) : socket_(io_ctx发生异常，可以输入更多信息再让我来回答或重试